package org.ricks.log.message;

/**
 * @author chenwei
 * @Description:参数日志信息
 * @date 2023/1/916:12
 */
class ParameterizedMessage extends AbstractMessage {
    private static final MessageAnalyzerManager CACHE = new MessageAnalyzerManager();
    private final Object[] args;

    ParameterizedMessage(String messagePattern, Object[] args) {
        super(messagePattern);
        this.args = this.handleArgs(args);
    }

    private Object[] handleArgs(Object[] args) {
        // 把传递的参数处理了，把非基本数据类型提交转为String对象
        for (int i = 0, len = args.length; i < len; i++) {
            args[i] = MessageHelper.preprocessingEnteringLogThreadBefore(args[i]);
        }
        return args;
    }

    @Override
    protected void onBuildMessage(StringBuilder sb) {
        CACHE.get(msg, MessageAnalyzer::new).build(sb, args);
    }
}
